{%extends "issue_base.html"%}

{%block head%}{{form.media}}{%endblock%}
{%block issue_body%}
{%if issue.draft_count or has_draft_message%}
  <div class="error">
    You have {%if issue.draft_count%}<b>{{issue.draft_count}} draft</b>
    comment{{issue.draft_count|pluralize}}{%endif%}
    {%if has_draft_message%}{%if issue.draft_count%}and {%endif%}a draft
    message{%endif%}.
    Drafts are not viewable by others.
  </div>
{%endif%}


{%if issue.description%}
  <h3><a id="issue-description-pointer"
     href="javascript:M_toggleSection('issue-description')"
     class="toggled-section opentriangle">
    Description</a></h3>
  <div id="issue-description">{{issue.description|safe}}
  </div>
{%endif%}


{%for patchset in patchsets%}
  <h3>
    <a id="ps-{{patchset.key.id}}-pointer"
       href="{%url codereview.views.show issue.key.id%}#ps{{patchset.key.id}}"
       onclick="M_toggleSectionForPS('{{issue.key.id}}', '{{patchset.key.id}}')"
       class="toggled-section {%if forloop.last%}opentriangle{%endif%}">
      Patch Set {{forloop.counter}}
      {%if patchset.message%}: {{patchset.message}}{%endif%}
      <span class="anchor">#</span>
    </a>
  </h3>

  {%if patchset.num_comments or patchset.n_drafts%}
    <div>
      <i>Total comments:</i> {{patchset.num_comments}}
      {%if patchset.n_drafts%}
        <span style="color:red">
          <b>+ {{patchset.n_drafts}} draft{{patchset.n_drafts|pluralize}}</b>
        </span>
      {%endif%}
    </div>
  {%endif%}

  <div id="ps-{{patchset.key.id}}"
  {%if forloop.last%}
       style="">
    {%include "patchset.html"%}
  {%else%}
       style="display:none">
  {%endif%}
  </div>
  {%if forloop.last%}
    <script language="JavaScript" type="text/javascript">
         <!--
         var lastPSId = {{patchset.key.id}};
         // -->
       </script>
  {%endif%}
{%endfor%}


{%if messages%}
  <h3>
    <a id="messages-pointer"
       href="javascript:M_toggleSection('messages')"
       class="toggled-section opentriangle">
      Messages
    </a>
  </h3>

  {%if messages%}
    <div><i>
    Total messages: {{messages|length}} ({{generated_messages|length}} generated)
    </i></div>
  {%endif%}

  <div id="messages">
    <div style="margin-bottom: .5em;">
      <a href="javascript:M_expandAllVisibleComments('cl', {{messages|length}})">
        Expand Messages</a>
      |
      <a href="javascript:M_collapseAllVisibleComments('cl', {{messages|length}})">
        Collapse Messages</a>
      {% if generated_messages %}
      |
      <a href="javascript:M_showGeneratedComments({{messages|length}})">
        Show Generated Messages</a>
      |
      <a href="javascript:M_hideGeneratedComments({{messages|length}})">
        Hide Generated Messages</a>
      {% endif %}
    </div>

    {%for message in messages%}
      <div class="message {%if message.issue_was_closed%}issue_was_closed{%endif%} {%if message.approval%}approval{%endif%} {%if message.disapproval%}disapproval{%endif%} {%if message.auto_generated %}generated{%endif%}"
           {%if message.auto_generated and messages|length != generated_messages|length and not display_generated_msgs %}style="display: none"{%endif%}
           id="{%if message.auto_generated %}generated-{%endif%}msg{{forloop.counter}}"
           name="{{forloop.counter0}}">
        <div class="header">
          <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr class="comment_title"
                onclick="M_switchChangelistComment({{forloop.counter0}})">
              <td style="padding-left: 5px; white-space: nowrap;">
                <b>{%nickname message.sender%}</b>
              </td>
              <td width="100%" style="overflow:hidden;">
                <table style="table-layout:fixed; white-space: nowrap;"
                       width="100%">
                  <tr>
                    <td>
                      <span style="white-space: nowrap; overflow: hidden;{%if forloop.last or last_user_message_index == forloop.counter0%} display: none;{%endif%}"
                           class="extra"
                           id="cl-preview-{{forloop.counter0}}">
                          {{message.text|truncatewords:15}}
                      </span>
                    </td>
                  </tr>
                </table>
              </td>
              <td align="right"
                  style="white-space: nowrap; padding-right: 5px; padding-left: 3px;">
                {{message.date|timesince}} ago
		({{message.date|date:"Y-m-d H:i:s T"}})
                <a href="#msg{{forloop.counter}}">#{{forloop.counter}}</a>
              </td>
            </tr>
          </table>
        </div>

        <div id="cl-comment-{{forloop.counter0}}"
             {%if forloop.last or last_user_message_index == forloop.counter0%}{%else%}style="display: none;"{%endif%}>
          <div class="message-body">
            {%if message.issue_was_closed%}
              <span class="extra-note">
                Message was sent while issue was closed.
              </span>
            {%endif%}
            <pre name="cl-message-{{forloop.counter0}}"
            >{{message.text|wordwrap:80|urlizetrunc:80}}</pre>
          </div>
          <div class="message-footer"></div>
        </div>

      </div>
    {%endfor%}

    <div>
      <a href="javascript:M_expandAllVisibleComments('cl', {{messages|length}})">
        Expand Messages</a>
      |
      <a href="javascript:M_collapseAllVisibleComments('cl', {{messages|length}})">
        Collapse Messages</a>
      {% if generated_messages %}
      |
      <a href="javascript:M_showGeneratedComments({{messages|length}})">
        Show Generated Messages</a>
      |
      <a href="javascript:M_hideGeneratedComments({{messages|length}})">
        Hide Generated Messages</a>
      {% endif %}
    </div>

  </div>

<script language="JavaScript" type="text/javascript">
<!--
var lastMsgID = {{messages|length}};
// -->
</script>

{%endif%}


<script language="JavaScript" type="text/javascript">
  <!--
    document.onkeydown = M_changelistKeyDown;
    var dashboardState = new M_DashboardState(window, 'patch', 'M_CLPatchMarker');
    var issueId = {{issue.key.id}};
    M_toggleIssueOverviewByAnchor();
  // -->
</script>


{%endblock issue_body%}
